﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Text.RegularExpressions;
using System.Configuration;
using System.Diagnostics;
using System.Runtime.Serialization.Json;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.IO;
using System.Text;
using Microsoft.Win32;
using System.Drawing;
using System.Threading;
using System.Net;
using System.Runtime.InteropServices;
namespace Piao
{

    static class Program
    {

        private static Mutex mut = new Mutex(true, "train");

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main(string[] args)
        {

             





            int maxProc = Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName).Length;
            if (maxProc > 10)
                return;

            if (args.Length > 0)
            {
                if (string.CompareOrdinal(args[0], "debug") == 0)
                    Debugger.Launch();


                WebProxyTest test = new WebProxyTest();
                test.ShowDialog();

                return;
            }


            if (!IsDotnet35Sp1Installed())
            {
                MessageBox.Show("需要安装 .netFX 3.5 SP1. Application exits.", "Warning");
                Process.Start("http://www.microsoft.com/downloads/zh-cn/details.aspx?FamilyID=ab99342f-5d1a-413d-8319-81da479ab0d7");
                return;
            }


            //use chinese calendar for datepicker
            System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("zh-CN");
            Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new MainForm());


        }

        static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
        {

            MessageBox.Show(
#if DEBUG
e.Exception.ToString()
#else
e.Exception.Message
#endif
, "Error", MessageBoxButtons.OK);
        }


        static bool IsDotnet35Sp1Installed()
        {

            RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.5");
            if (key != null)
            {
                int sp = (int)key.GetValue("SP", -1);
                return sp > 0;
            }
            return false;
        }
    }
}
